﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CoreData;
using ActionServices;
using Helper;

namespace ZidoniCMS.Controllers
{
    public class CategoryController : BaseController
    {
        //
        // GET: /Category/
        public CategoryController(ICategoryActionService _category, IProductActionService _product,
            IConfigurationActionService _config, ICategoryArticleActionService cateart, IArticleActionService art)
            : base(_category, _product, _config, cateart,art)
        { }


        /// <summary>
        /// Menu danh mục sản phẩm
        /// </summary>
        /// <returns></returns>
        public ActionResult _NavigationCategory()
        {
            var model = CategoryService.GetListByLINQ(x => x.Active == true).ToList();
            return PartialView(model);
        }
        /// <summary>
        /// Menu danh mục sản phẩm trong trang Category
        /// </summary>
        /// <param name="CatId"></param>
        /// <returns></returns>
        public ActionResult _GetChildCategory(int CatId) {
            var model = CategoryService.GetListByLINQ(x=> x.Active== true && x.ParentID==CatId).ToList();
            return PartialView(model);
        }
        /// <summary>
        /// Những danh mục các sản phẩm tiêu biểu show ở trang chủ
        /// </summary>
        /// <returns></returns>
        public ActionResult _CategoryListOnHome() {
            var tempCate = CategoryService.GetListByLINQ(x => x.Active == true && x.ShowHomePage == true).ToList();
            var ListCate = new List<Category>();
            foreach (var item in tempCate)
            {
                var product = ProductService.GetListByLINQ(x => x.Active == true && x.CateID == item.ID).ToList();
                if (product.Count() > 0)
                {
                    ListCate.Add(item);
                }
            }
            return View(ListCate);
        }
    }
}
